import axios from 'axios';
import vue from 'vue';

axios.defaults.headers.post['Content-Type'] = 'application/json'
// 创建axios实例
const service = axios.create({
  baseURL: "/local/", // api的base_url axios.defaults.baseURL = 'http://localhost:8080/';
  timeout: 5000                  // 请求超时时间
});

// request拦截器
service.interceptors.request.use(config => {
  // Do something before request is sent
  return config;
}, error => {
  // Do something with request error
  console.log(error); // for debug
  Promise.reject(error);
})

// respone拦截器
service.interceptors.response.use(
  response => response,
  error => {
    console.log('err' + error);// for debug
    // vue.$Message.error({
    //                 message: error.message,
    //                 duration: 5 * 1000,
    //                 closable: true
    //             });
    return Promise.reject(error);
  }
)

export default service;
